package com.ruoyi.web.controller.system;



import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TErrorlog;
import com.ruoyi.system.service.ITErrorlogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备故障信息Controller
 *
 * @author ruoyi
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/system/ErrorLog")
public class TErrorlogController extends BaseController
{
    @Autowired
    private ITErrorlogService tErrorlogService;

    /**
     * 查询设备故障信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:ErrorLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(TErrorlog tErrorlog)
    {
        startPage();
        String[] errdatas = tErrorlog.getErrdates();
        if (errdatas != null && errdatas.length > 1) {
            tErrorlog.setErrStartTime(errdatas[0]);
            tErrorlog.setErrEndsTime(errdatas[1]);
        }
        String[] handledates = tErrorlog.getHandledates();
        if (handledates != null && handledates.length > 1) {
            tErrorlog.setHandleStartTime(handledates[0]);
            tErrorlog.setHandleEndsTime(handledates[1]);
        }
        List<TErrorlog> list = tErrorlogService.selectTErrorlogList(tErrorlog);
        return getDataTable(list);
    }

    /**
     * 导出设备故障信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:ErrorLog:export')")
    @Log(title = "设备故障信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TErrorlog tErrorlog)
    {
        List<TErrorlog> list = tErrorlogService.selectTErrorlogList(tErrorlog);
        ExcelUtil<TErrorlog> util = new ExcelUtil<TErrorlog>(TErrorlog.class);
        util.exportExcel(response, list, "设备故障信息数据");
    }

    /**
     * 获取设备故障信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ErrorLog:query')")
    @GetMapping(value = "/{decID}")
    public AjaxResult getInfo(@PathVariable("decID") String decID)
    {
        return success(tErrorlogService.selectTErrorlogByDecID(decID));
    }

    /**
     * 新增设备故障信息
     */
    @PreAuthorize("@ss.hasPermi('system:ErrorLog:add')")
    @Log(title = "设备故障信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TErrorlog tErrorlog)
    {
        return toAjax(tErrorlogService.insertTErrorlog(tErrorlog));
    }

    /**
     * 修改设备故障信息
     */
    @PreAuthorize("@ss.hasPermi('system:ErrorLog:edit')")
    @Log(title = "设备故障信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TErrorlog tErrorlog)
    {
        return toAjax(tErrorlogService.updateTErrorlog(tErrorlog));
    }

    /**
     * 删除设备故障信息
     */
    @PreAuthorize("@ss.hasPermi('system:ErrorLog:remove')")
    @Log(title = "设备故障信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{decIDs}")
    public AjaxResult remove(@PathVariable String[] decIDs)
    {
        return toAjax(tErrorlogService.deleteTErrorlogByDecIDs(decIDs));
    }
}
